#ifndef LINKWIKI_H
#define LINKWIKI_H

#include <wiki/wiki.h>

#include <qrcutil.h>

class LinkWiki : public Wiki
{
public:
    LinkWiki();

public:
    WIKI_AUTOLOAD
    WIKI_USE_LIST
    WIKI_USE_URL
};

#define LINKWIKI_INNER(x,y,z)                           \
public:                                             \
    virtual QString name() override { return x; }   \
    virtual QString prefix() override { return z; } \
    virtual QList<QListWidgetItem*> searching_item(const QString &text) override { \
        QList<QListWidgetItem*> list; \
        foreach(auto line, QR(y).split("\n", Qt::SkipEmptyParts)) { \
            auto title = line.mid(line.indexOf(">")+1); \
            title = title.mid(0, title.indexOf("<"));\
            auto href = line.mid(line.indexOf("href=\"")+6);\
            href = href.mid(0, href.indexOf("\">")); \
    \
            if (text.isEmpty() || title.contains(text, Qt::CaseInsensitive)) { \
                auto item = newItem(); \
                item->setText(title); \
                item->setData(990, href); \
                list << item; \
            } \
        } \
        return list; \
    } \
    virtual QString content_item(const QListWidgetItem *item) override { \
        return prefix() + item->data(990).toString(); \
    } \


#define LINKWIKI(a,x,y,z)   \
class a : public LinkWiki   \
{                           \
public:                     \
    a() {}                  \
    LINKWIKI_INNER(x, y, z) \
};                          \

#include "bycsdn.h"
#include "byzhihu.h"

LINKWIKI(GitScmBook, "中文版《Git Book》", "://gitscmbook.txt", "https://git-scm.com/")

LINKWIKI(ChinaGovLink, "中国政府网站", "://china-govlinks.txt", "")
LINKWIKICSDN(TerryW, "TerryW", "://csdnlinks/terryw.txt", "")
LINKWIKICSDN(CsdnMiscLinks, "Csdn 链接源", "://csdnlinks/misc.txt", "")

LINKWIKICSDN(TopeetCsdnLinks, "北京讯为 - Csdn", "://csdnlinks/topeet.txt", "")
LINKWIKI(TopeetVideoLinks, "北京讯为 - 视频教程", "://bilibililinks/topeet-videos.txt", "")
LINKWIKI(TopeetBaijiahaoLinks, "北京讯为 - 百家号", "://baijiahaolinks/topeet.txt", "")

LINKWIKI(ForgotFunVideoLinks, "佐须之男 - bilibili", "://bilibililinks/forgotfun.txt", "")
LINKWIKI(ForgotFunOrg, "佐须之男 - ForgotFun", "://forgotfun.org.txt", "")

LINKWIKI(ArchWikiLinks, "Arch Wiki", "://archwiki.txt", "https://wiki.archlinuxcn.org")

LINKWIKIZHIHU(AndroidXiaoShuai, "知乎专栏 - Android 小帅", "://zhihulinks/androidxiao-shuai.txt", "");

#endif // LINKWIKI_H
